home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.09 Sep 93 / BitMapper ƒ / BitMapper.c next >
Encoding:
C/C++ Source or Header  |  1993-07-02  |  3.2 KB  |  160 lines  |  [TEXT/KAHL]

  1. /********************************/
  2. /*                                */
  3. /*  BitMapper Code                */
  4. /*    Copyright 1992, Dave Mark      */
  5. /*                                */
  6. /********************************/
  7.  
  8. #define    kMoveToFront        (WindowPtr)-1L
  9.  
  10. const short    kBackgroundPictID =        128;
  11. const short    kForegroundPictID =        129;
  12.  
  13.  
  14. /***************/
  15. /*  Functions  */
  16. /***************/
  17.  
  18. void        ToolboxInit( void );
  19. WindowPtr    WindowInit( void );
  20. PicHandle    LoadPicture( short resID );
  21. GrafPtr        CreateBitMap( const Rect *rPtr );
  22.  
  23.  
  24. /****************** main ***************************/
  25.  
  26. void    main( void )
  27. {
  28.     Rect        r;
  29.     GrafPtr        backPortPtr, forePortPtr, mixerPortPtr;
  30.     WindowPtr    window;
  31.     PicHandle    backPict, forePict;
  32.     Point        p;
  33.     
  34.     ToolboxInit();
  35.     window = WindowInit();
  36.     
  37.     backPict = LoadPicture( kBackgroundPictID );
  38.     r = (**backPict).picFrame;
  39.     OffsetRect( &r, -r.left, -r.top );
  40.     
  41.     backPortPtr = CreateBitMap( &r );    /* Leaves backPortPtr as current port */
  42.     DrawPicture( backPict, &r );
  43.     
  44.     mixerPortPtr = CreateBitMap( &r );    /* Leaves mixerPortPtr as current port */
  45.     
  46.     forePict = LoadPicture( kForegroundPictID );
  47.     r = (**forePict).picFrame;
  48.     OffsetRect( &r, -r.left, -r.top );
  49.     
  50.     forePortPtr = CreateBitMap( &r );    /* Leaves forePortPtr as current port */
  51.     DrawPicture( forePict, &r );
  52.     
  53.     HideCursor();
  54.     
  55.     while ( !Button() )
  56.     {
  57.         CopyBits( &(backPortPtr->portBits), &(mixerPortPtr->portBits),
  58.                 &(backPortPtr->portBits.bounds), &(mixerPortPtr->portBits.bounds),
  59.                 srcCopy, nil );
  60.         
  61.         GetMouse( &p );
  62.         SetPort( window );
  63.         GlobalToLocal( &p );
  64.         r = forePortPtr->portBits.bounds;
  65.         OffsetRect( &r, p.h, p.v );
  66.         
  67.         CopyBits( &(forePortPtr->portBits), &(mixerPortPtr->portBits),
  68.                 &(forePortPtr->portBits.bounds), &r,
  69.                 srcOr, nil );
  70.                 
  71.         CopyBits( &(mixerPortPtr->portBits), &(window->portBits),
  72.                 &(mixerPortPtr->portBits.bounds), &(window->portRect),
  73.                 srcCopy, nil );
  74.     }
  75. }
  76.  
  77.  
  78. /****************** ToolboxInit *********************/
  79.  
  80. void    ToolboxInit( void )
  81. {
  82.     InitGraf( &thePort );
  83.     InitFonts();
  84.     InitWindows();
  85.     InitMenus();
  86.     TEInit();
  87.     InitDialogs( nil );
  88.     InitCursor();
  89. }
  90.  
  91.  
  92. /****************** WindowInit ***********************/
  93.  
  94. WindowPtr    WindowInit( void )
  95. {
  96.     WindowPtr    window;
  97.     PicHandle    pic;
  98.     Rect        r;
  99.     
  100.     pic = LoadPicture( kBackgroundPictID );
  101.     r = (**pic).picFrame;
  102.     
  103.     OffsetRect( &r, 20 - r.left, 50 - r.top );
  104.     
  105.     window = NewWindow( nil, &r, "\pBitMapper", true, noGrowDocProc,
  106.                             kMoveToFront, false, 0L );
  107.     
  108.     return( window );
  109. }
  110.  
  111.  
  112. /****************** LoadPicture *********************/
  113.  
  114. PicHandle    LoadPicture( short resID )
  115. {
  116.     PicHandle    picture;
  117.     
  118.     picture = GetPicture( resID );
  119.     
  120.     if ( picture == nil )
  121.     {
  122.         SysBeep( 10 );    /*  Couldn't load the PICT resource!!!  */
  123.         ExitToShell();
  124.     }
  125. }
  126.  
  127.  
  128. /****************** CreateBitMap *********************/
  129.  
  130. GrafPtr CreateBitMap( const Rect *rPtr )
  131. {
  132.     short        i;
  133.     BitMap        *bPtr;
  134.     GrafPtr        g;
  135.     
  136.     g = (GrafPtr)NewPtr( sizeof(GrafPort) );
  137.     if ( g == nil )
  138.         SysBeep(20);
  139.         
  140.     bPtr = (BitMap *)NewPtr( sizeof( BitMap ) );
  141.     if ( bPtr == nil )
  142.         SysBeep( 20 );
  143.     bPtr->bounds = *rPtr;
  144.     
  145.     bPtr->rowBytes = (rPtr->right - rPtr->left + 7) /8;
  146. /*    i = bPtr->rowBytes / 2;
  147.     if ( (2 * i) != bPtr->rowBytes )
  148.         bPtr->rowBytes ++;*/
  149.     
  150.     i = rPtr->bottom - rPtr->top;
  151.     bPtr->baseAddr = NewPtr( bPtr->rowBytes * i );
  152.     
  153.     if ( bPtr->baseAddr == nil )
  154.         SysBeep( 20 );
  155.     
  156.     OpenPort( g );
  157.     SetPortBits( bPtr );
  158.     
  159.     return( g );
  160. }